package com.codejiwei.flink.practice;

import com.codejiwei.flink.entity.WaterSensor;
import com.codejiwei.flink.sink.MyJDBCSink;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.ArrayList;

/**
 * @author jiwei
 * @description
 * @date 2023/5/22 17:35
 */
public class Flink_Sink_Jdbc {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
////        env.setRuntimeMode(RuntimeExecutionMode.BATCH);
//        env.setRuntimeMode(RuntimeExecutionMode.AUTOMATIC);


        ArrayList<WaterSensor> waterSensors = new ArrayList<>();
        waterSensors.add(new WaterSensor("sensor_3", 1607527992000L, 20));
        waterSensors.add(new WaterSensor("sensor_4", 1607527994000L, 50));
        waterSensors.add(new WaterSensor("sensor_5", 1607527996000L, 50));
        waterSensors.add(new WaterSensor("sensor_6", 1607527993000L, 10));
        waterSensors.add(new WaterSensor("sensor_7", 1607527995000L, 30));

        env.fromCollection(waterSensors)
                .addSink(new MyJDBCSink());

        env.execute();

    }
}
